<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>


	
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  height:800pxpx;'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 200px;">按产品券商汇总表 :  </span>
				<span style="font-size: medium; padding: 10px;">日期:</span>
				<el-select v-model="date_choice" size="small" clearable filterable placeholder="请选择">
					<el-option v-for="item in date_options" :key="item.label" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
				<span style="padding-left:30px;">只看使用中:</span>
				<el-switch style="margin-left: 30px;height: 30px; "
				  v-model="in_use_flag"
				  active-color="#13ce66"
				  inactive-color="#ff4949">
				</el-switch>
				<div style="padding-left: 10px;">
					<el-button size="mini" type="success" @click="get_exchange_arrange()">刷新</el-button>
					
					<el-button size="mini" type="primary" @click="exportCSV1()">导出</el-button>
					
				</div>
				
				
				
				<span style="font-size: 20px;padding-left: 150px;">选中总金额:{{(quanshang_total_asset/10000).toFixed(1)}} 万 :  </span>
			

				
			</div>

			<el-table ref="singleTable" :data="arrange_data"  height="700px" border size='small' :fit='true'  @selection-change="handleSelectionChange"
				:style="'width:'+(screenWidth*1.0)+'px;' ">
				<el-table-column   type="selection" label="ID"  width="180"></el-table-column>
				<el-table-column prop="account_brokerage" label="券商"  sortable  align></el-table-column>
				<el-table-column prop="account_brokerage_total" label="券商"  sortable  align></el-table-column>
				<el-table-column prop="total_asset" label="最新资产汇总"  sortable align></el-table-column>
				<el-table-column prop="total_asset" label="汇总到万"  sortable align>
					<template slot-scope="scope">
						<span  style="color:darkred;"> {{(scope.row['total_asset']/10000).toFixed(1)}}万 </span> 
					</template>
				</el-table-column>
			</el-table>
			
		</div>
	
		<div class="table_container" :style="'width: 90%;  overflow: hidden;  height:800px'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 200px;">按产品策略汇总表 : （区分中性产品） </span>
				<span style="font-size: medium; padding: 10px;">日期:</span>
				<el-select v-model="date_choice" size="small" clearable filterable placeholder="请选择">
					<el-option v-for="item in date_options" :key="item.label" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
				<span style="padding-left:30px;">只看使用中:</span>
				<el-switch style="margin-left: 30px;height: 30px; "
				  v-model="in_use_flag"
				  active-color="#13ce66"
				  inactive-color="#ff4949">
				</el-switch>
				<div style="padding-left: 10px;">
					<el-button size="mini" type="success" @click="get_exchange_arrange3()">刷新</el-button>
					<el-button size="mini" type="primary" @click="exportCSV2()">导出</el-button>
				</div>
				<span style="font-size: 20px; padding-left: 150px;">选中总金额:{{(strategy_total_asset3/10000).toFixed(1)}} 万 :  </span> 
			</div>
		
			<el-table ref="singleTable" :data="arrange_data3"  height="700px" border size='small' :fit='true'  @selection-change="handleSelectionChange3"
				:style="'width:'+(screenWidth*1.0)+'px;'">
				<el-table-column   type="selection" label="ID"  width="180"></el-table-column>
				<el-table-column prop="product_properties" label="产品策略"  sortable  align></el-table-column>
				<el-table-column prop="account_type" label="账户类型"  sortable  align></el-table-column>
				<el-table-column prop="product_strategy" label="账户策略"  sortable  align></el-table-column>
				<el-table-column prop="count" label="count"  sortable  align></el-table-column>
				<el-table-column prop="total_asset" label="最新资产汇总"  sortable align></el-table-column>
				<el-table-column prop="total_asset" label="汇总到万"  sortable align>
					<template slot-scope="scope">
						<span  style="color:darkred;"> {{(scope.row['total_asset']/10000).toFixed(1)}}万 </span> 
					</template>
				</el-table-column>
				
			</el-table>
		</div>
		<div style="padding-bottom: 300px;" ></div>
		<!-- <div class="table_container" :style="'width: 90%;  overflow: hidden;  height:'+(winHeight/2)+'px;'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 200px;">按账户类型汇总表 : （不区分中性产品） </span>
				<div>
					<el-button size="mini" type="success" @click="get_exchange_arrange2()">刷新</el-button>
				</div>
				<span style="font-size: 20px; padding-left: 150px;">选中总金额:{{(strategy_total_asset/10000).toFixed(1)}} 万 :  </span> 
			</div>
		
			<el-table ref="singleTable" :data="arrange_data2"  height="100%" border size='small' :fit='true'  @selection-change="handleSelectionChange2"
				:style="'width:'+(screenWidth*1.0)+'px;'">
				<el-table-column   type="selection" label="ID"  width="180"></el-table-column>
				<el-table-column prop="account_type" label="账户类型"  sortable  align></el-table-column>
				<el-table-column prop="product_strategy" label="策略类型"  sortable  align></el-table-column>
				<el-table-column prop="total_asset" label="最新资产汇总"  sortable align></el-table-column>
				<el-table-column prop="total_asset" label="汇总到万"  sortable align>
					<template slot-scope="scope">
						<span  style="color:darkred;"> {{(scope.row['total_asset']/10000).toFixed(1)}}万 </span> 
					</template>
				</el-table-column>
				
			</el-table>
		</div>
		 -->
		
		
	</div>
</template>

<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				checkflag: false,
				core_pos: [],
				pos_index_item: '',
				product_choice: "",
				in_use_flag:true,
				quanshang_total_asset:0,
				strategy_total_asset3:0,
				strategy_total_asset:0,
				product_options: [],
				target_pos_index_options: [],
				date_choice: "",
				date_options: [],
				tableData: [],
				currentRow: null,
				inoutflag:false,
				count: 0,
				exchange_detail: [],
				LP_account_list: [],
				fix_account: {},
				visible: false,
				visible2: false,
				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				moneyindex: "0",
				arrange_data: [],
				arrange_data2: [],
				arrange_data3: []
				
				

			}
		},
		components: {
			headTop,
		},



		activated() {

			// console.log("当前登入用户", this.$store.state.adminInfo.name);
			//    if (this.tradesysPermission_list.indexOf (this.$store.state.adminInfo.permission) ==-1) {
			// 	console.log(this.$store.state.adminInfo.name,"未登入")
			// 	this.$message({type: 'error',	message: '没有权限',});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},
		created() {
			this.get_date_last()
			this.get_exchange_arrange()
			this.get_exchange_arrange2()
			this.get_exchange_arrange3()
		},
		computed: {
			
		},

		methods: {
			
			
			
			handlefixaccount(index, row) {
				console.log("row", row)
				this.fix_account = row
				this.visible2 = true
			},
			get_date_last() {
				var that = this;
				
				
				let sql =
					" select distinct date_format(date,'%Y-%m-%d') as date_str  from `LP_account_day` where date>'20230101' order by date_str desc;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.date_options = []
						that.date_choice=response.data[0]['date_str']
						//for (var i = 0; i < response.data.length; i++) {
						for (var i =0; i <=response.data.length; i++) {
							let char = {
								value: response.data[i]['date_str'],
								label: response.data[i]['date_str'],
							};
							that.date_options.push(char);
						}
					} else {
						console.log(response.data.statusCode);
					}
				})
			
			},
			
			
			
			exportCSV1(){ //导出CSV
			   //生成文件
			   let arr = ['券商,券商完整,总资产'];	//第一行，列名。csv文件会默认根据逗号分割成列
			   let data = this.arrange_data;	//需要导出的列表
			   
			   for(let i=0;i<this.arrange_data.length;i++){
				   let temp = [];
				   temp.push(data[i].account_brokerage)
				   temp.push(data[i].account_brokerage_total)
				   temp.push(data[i].total_asset)
				   arr.push(temp.join(','));	//添加每一行的内容
			   }
			   console.log(arr)
			   let content = "data:text/csv;charset=utf-8,\ufeff" + arr.join('\n');	//文件格式+文件内容，\n换行
			
			   //下载文件
			   var link = document.createElement("a");
			   link.setAttribute("href", content);
			   link.setAttribute("download", "券商汇总.csv");
			   link.click();
			},
			exportCSV2(){ //导出CSV
			   //生成文件
			   let arr = ['产品策略,账户类型,账户策略,个数,最新资产汇总'];	//第一行，列名。csv文件会默认根据逗号分割成列
			   let data = this.arrange_data3;	//需要导出的列表
			   
			   for(let i=0;i<this.arrange_data3.length;i++){
				   let temp = [];
				   temp.push(data[i].product_properties)
				   temp.push(data[i].account_type)
				   temp.push(data[i].product_strategy)
				   temp.push(data[i].count)
				   temp.push(data[i].total_asset)
				   arr.push(temp.join(','));	//添加每一行的内容
			   }
			   console.log(arr)
			   let content = "data:text/csv;charset=utf-8,\ufeff" + arr.join('\n');	//文件格式+文件内容，\n换行
			
			   //下载文件
			   var link = document.createElement("a");
			   link.setAttribute("href", content);
			   link.setAttribute("download", "券商汇总.csv");
			   link.click();
			},
	
		
		      handleSelectionChange(val) {
		        this.multipleSelection = val;
				let total_asset=0;
				for(let i=0;i<this.multipleSelection.length;i++){
					// console.log(this.multipleSelection[i].total_asset) 	
					total_asset+= this.multipleSelection[i].total_asset
				}
				this.quanshang_total_asset=total_asset
				// console.log(total_asset)
			
			},
			handleSelectionChange2(val) {
				this.multipleSelection2 = val;
				let total_asset=0;
				for(let i=0;i<this.multipleSelection2.length;i++){
					// console.log(this.multipleSelection[i].total_asset) 	
					total_asset+= this.multipleSelection2[i].total_asset
				}
				this.strategy_total_asset=total_asset
				// console.log(total_asset)
							
			},
		
			handleSelectionChange3(val) {
				this.multipleSelection3 = val;
				let total_asset=0;
				for(let i=0;i<this.multipleSelection3.length;i++){
					// console.log(this.multipleSelection[i].total_asset) 	
					total_asset+= this.multipleSelection3[i].total_asset
				}
				this.strategy_total_asset3=total_asset
				// console.log(total_asset)
							
			},
			
		
			get_exchange_arrange2() {
				var that = this;
				console.log(that.lpapi2)
				let in_use1=''
				if(this.in_use_flag ){
					 in_use1='yes'
				}
				else{
					 in_use1=''
				}
				
				// let sql ="select * ,date_format(begin_date,'%Y-%m-%d') as begin_date_kk from `LP_product_dict` ;"
				let sql = "SELECT  pc.account_type,pc.product_strategy,sum(pas.total_asset) as total_asset  FROM  LP_account_list pc  \
LEFT JOIN (   SELECT    total_asset,account FROM   LP_account_trade_qry  \
WHERE    (account, datetime) IN (   SELECT    account,     MAX(datetime)  FROM   LP_account_trade_qry  \
 where total_asset>0  and date >= '"+this.date_choice+"' - INTERVAL 5 DAY  and date<= '"+this.date_choice+"'   GROUP BY   account  )  \
) pas \
 ON pc.account = pas.account where   pc.check_flag like '%"+in_use1+"%'  \
GROUP BY pc.account_type,pc.product_strategy order by pc.account_type,pc.product_strategy;" 
			
				that.arrange_data2 = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'data2')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data2 = []
						} else {
							that.arrange_data2 = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},
		
		
		
			get_exchange_arrange() {
				var that = this;
				console.log(that.lpapi2)
				let in_use1=''
				if(this.in_use_flag ){
					 in_use1='yes'
				}
				else{
					 in_use1=''
				}
				
				
				// let sql ="select * ,date_format(begin_date,'%Y-%m-%d') as begin_date_kk from `LP_product_dict` ;"
// 				let sql = " SELECT  pc.account_brokerage,pc.account_brokerage_total, sum(pas.total_asset) as total_asset FROM  LP_product_dict pc  \
// LEFT JOIN (   SELECT    total_asset,account FROM   LP_account_trade_qry  \
// WHERE    (account, datetime) IN (   SELECT    account,     MAX(datetime)  FROM   LP_account_trade_qry  \
//  where total_asset>0 and date >= CURDATE() - INTERVAL 5 DAY \
// GROUP BY   account  )  \
// ) pas ON pc.account_id = pas.account where  pc.in_use='yes' and  account_brokerage IS NOT NULL AND TRIM(account_brokerage) <> '' \
// GROUP BY pc.account_brokerage_total,account_brokerage;"
				
				let sql =" SELECT   pc.account_brokerage, pc.account_brokerage_total ,  sum(pas.total_asset) as total_asset , count(pas.total_asset) as count FROM \
(SELECT view_config_account.account_brokerage_total  ,view_config_account.account_brokerage ,view_config_account.qry_account \
	from view_config_account,config_product where view_config_account.product_name=config_product.product_name  and  \
 view_config_account.use_flag like '%"+in_use1+"%'    and config_product.in_use like 'yes'  and  view_config_account.account_brokerage IS NOT NULL AND TRIM(view_config_account.account_brokerage) <> '') pc   \
LEFT JOIN (   SELECT    total_asset,account FROM   LP_account_trade_qry   \
WHERE    (account, datetime) IN (   SELECT    account,     MAX(datetime)  FROM   LP_account_trade_qry   \
 where total_asset>0  and date >= '"+this.date_choice+"' - INTERVAL 5 DAY  and date<= '"+this.date_choice+"'    \
GROUP BY   account  )   \
) pas ON pc.qry_account = pas.account   \
GROUP BY pc.account_brokerage_total,account_brokerage;" 
			
			
				that.arrange_data = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'LP_product_dict')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data = []
						} else {
							that.arrange_data = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},
			get_exchange_arrange3() {
				var that = this;
				console.log(that.lpapi2)
				let in_use1=''
				if(this.in_use_flag ){
					 in_use1='yes'
				}
				else{
					 in_use1=''
				}
			
				
				// let sql ="select * ,date_format(begin_date,'%Y-%m-%d') as begin_date_kk from `LP_product_dict` ;"
// 				let sql = " SELECT   pc.product_strategy, pc.account_strategy ,pc.account_type, sum(pas.total_asset) as total_asset , count(pas.total_asset) as count FROM  LP_product_dict pc  \
// LEFT JOIN (   SELECT    total_asset,account FROM   LP_account_trade_qry  \
// WHERE    (account, datetime) IN (   SELECT    account,     MAX(datetime)  FROM   LP_account_trade_qry  \
//  where total_asset>0 and date >= CURDATE() - INTERVAL 31 DAY \
// GROUP BY   account  )  \
// ) pas ON pc.account_id = pas.account where  pc.in_use='yes' and  account_brokerage IS NOT NULL AND TRIM(account_brokerage) <> '' \
// GROUP BY pc.product_strategy,pc.account_strategy,account_type;"
				let sql ="	SELECT   pc.product_properties,pc.product_strategy , pc.account_type, sum(pas.total_asset) as total_asset , count(pas.total_asset) as count FROM   \
				(SELECT config_product.product_properties  ,view_config_account.product_strategy  ,view_config_account.account_type ,view_config_account.qry_account \
				  from view_config_account,config_product where view_config_account.product_name=config_product.product_name  and  \
				 view_config_account.use_flag like '%"+in_use1+"%'    and config_product.in_use like 'yes%'  and  view_config_account.account_brokerage IS NOT NULL AND TRIM(view_config_account.account) <> '') pc   \
				LEFT JOIN (   SELECT    total_asset,account FROM   LP_account_trade_qry   \
				WHERE    (account, datetime) IN (   SELECT    account,     MAX(datetime)  FROM   LP_account_trade_qry   \
				 where total_asset>0  and date >= '"+this.date_choice+"' - INTERVAL 5 DAY  and date<= '"+this.date_choice+"'    \
				GROUP BY   account  )   \
				) pas ON pc.qry_account = pas.account   \
				GROUP BY pc.product_properties,pc.product_strategy,account_type; \
				"
				
				
				
			
				that.arrange_data3 = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'LP_product_dict')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data3 = []
						} else {
							that.arrange_data3 = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},


			

		},
	}
</script>

<style>
	.el-table .bacOrangeRed {
		background: OrangeRed;
	}

	.el-table .bacorange {
		background: orange;
	}

	.el-table .success-row {
		background: grey;
		color: white;
	}

	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.el-table .grey {
		background: Silver;
	}

	.el-table .DarkGray {
		background: DarkGray;
	}

	.el-table .LightCoral {
		background: LightCoral;
		color: white;
	}

	.el-table .LimeGreen {
		background: LimeGreen;
	}

	.el-table .green {
		background: green;
	}

	.el-table .LightSlateGray {
		background: LightSlateGray;
	}

	.el-table .red {
		background: red;
		color: white;
	}

	.el-table .orange {
		background: NavajoWhite;
		color: black;
	}

	.el-table .blue {
		background: blue;
	}

	.el-table .purple {
		background: Violet;
		color: black;
	}

	.el-table .LightSteelBlue {
		background: LightSteelBlue;
	}

	.el-table .Goldenrod {
		background: Goldenrod;
	}

	.el-table .xingmu {
		background: Goldenrod;
		color: red;
		font-weight: bold;

	}


	.el-table .black {
		background: black;
		color: white;
	}

	.el-table .green {
		background: green;
		color: white;
	}

	.el-table .CornflowerBlue {
		background: CornflowerBlue;
		color: white;
	}

	.el-table .DodgerBlue {
		background: DodgerBlue;
	}
</style>
